/**
 * 
 */
package edu.ucr.cs.dblab.acestore.base.datatypes;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.nio.ByteBuffer;

/**
 * @author jarod
 * @created Jan 11, 2011
 */
public interface ISerDeserializer<T> {
	
	/**
	 * Deserialize a record from a byte buffer at the given
	 * offset and length.
	 * 
	 * @param buf
	 * @param offset
	 * @param length
	 * @return
	 */
	public T deserialize(ByteBuffer buf, int offset, int length) throws IOException;
	
	/**
	 * Deserialize a record from a byte array.
	 * 
	 * @param buf
	 * @return
	 */
	public T deserialize(byte[] buf, int offset, int length) throws IOException;
	
	public T deserialize(DataInput in) throws IOException;
	
	public T deserialize(String str) throws IOException;
	
	/**
	 * Serialize a record into a byte array.
	 * 
	 * @param data
	 * @return
	 */
	public byte[] serialize(T data) throws IOException;
	
	public byte[] serialize(String str) throws IOException;
	
	public void serialize(T data, DataOutput out) throws IOException;
	
	public int getTypeIndex();
	
	public int getTypeSize();
	
	/**
	 * Compare two objects in binary
	 * @param b1
	 * @param s1
	 * @param l1
	 * @param b2
	 * @param s2
	 * @param l2
	 * @return
	 */
	public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2) throws IOException;
	
	/**
	 * Compare with the specific type.
	 * 
	 * @param anotherValue
	 * @return
	 */
	public int compare(T value1, T value2);
}
